﻿<link rel="stylesheet" type="text/css" href="/easyui/themes/default/easyui.css">
<link rel="stylesheet" type="text/css" href="/easyui/themes/icon.css">
<link rel="stylesheet" type="text/css" href="/easyui/themes/color.css">
<link rel="stylesheet" type="text/css" href="https://www.jeasyui.com/easyui/demo/demo.css">
<link rel="stylesheet" type="text/css" href="/easyui/portal/portal.css">
<#include "/common/easyui-js.html">
<script type="text/javascript" src="/easyui/portal/jquery.portal.js"></script>
<script type="text/javascript" src="/easyui/ChinesePY.js"></script>
<script type="text/javascript" src="/lib/layer/2.4/layer.js"></script>
<#include "/common/loading.html">
<html>
<head>
    <style type="text/css">
        .title{
            font-size:16px;
            font-weight:bold;
            padding:20px 10px;
            background:#eee;
            overflow:hidden;
            border-bottom:1px solid #ccc;
        }
        .t-list{
            padding:5px;
        }
    </style>
    <script>
        $(function(){
            $('#pp').portal({
                border:true,
                fit:true
            });
        });
    </script>
</head>
<body class="easyui-layout">
<div region="north" class="title" border="false" style="height:80px;">

    <table cellpadding="5">
        <tr>
            <td colspan="2" align="center"><a href="#" class="easyui-linkbutton"  id="read" style="width:80px;height: 50px"><span style="font-size: 20px;font-weight: 900">读卡</span></a></td>
            <td colspan="2" align="center"><a href="#" class="easyui-linkbutton"  id="collection" style="width:80px;height: 50px"><span style="font-size: 20px;font-weight: 900">采集</span></a></td>
            <td colspan="2" align="center"><a href="#" class="easyui-linkbutton"  id="save" style="width:80px;height: 50px"><span style="font-size: 20px;font-weight: 900">保存</span></a></td>
            <td colspan="2" align="center"><a href="#" class="easyui-linkbutton"  id="write" style="width:80px;height: 50px"><span style="font-size: 20px;font-weight: 900">写卡</span></a></td>
            <td colspan="2" align="center"><a href="#" class="easyui-linkbutton"  id="print" style="width:80px;height: 50px"><span style="font-size: 20px;font-weight: 900">打印</span></a></td>
            <td colspan="2" align="center"><a href="#" class="easyui-linkbutton"  id="reset" style="width:80px;height: 50px"><span style="font-size: 20px;font-weight: 900">重置</span></a></td>
            <td><span style="font-size: 20px;font-weight: 900;color: #CCCC33">1#秤点</span></td>
        </tr>
    </table>
</div>
<div region="center" border="false">
    <div id="pp" style="position:relative;margin-left: 0px">
        <div style="width:48%;padding-right: 10px">
            <div  style="text-align:center;background:#222222;height:180px;">
                <span id="sec" style="color:#ff0509;line-height: 165px;font-size: 135px;m">000000</span>
            </div>
            <div title="重量信息采集" style="text-align:center;height:400px">
                <table cellpadding="5">
                    <tr>
                        <td><span style="color: black;font-size: 20px;font-weight: 900">磅单号</span></td>
                        <td><input class="easyui-textbox" type="text" name="measureId" id="measureId"  style="width:200px;"></input></td>
                        <td><span style="color: black;font-size: 20px;font-weight: 900">关闭标记</span></td>
                        <td><input class="easyui-textbox" type="text" name="closeSymbol" id="closeSymbol"  style="width:200px;"></input></td>
                    </tr>
                    <tr>
                        <td><span style="color: black;font-size: 20px;font-weight: 900">毛重</span></td>
                        <td><input class="easyui-textbox" type="text" name="gross" id="gross"  style="width:200px;"></input></td>
                        <td><span style="color: black;font-size: 20px;font-weight: 900">毛重时间</span></td>
                        <td><input class="easyui-textbox" type="text" name="grossTime"  id="grossTime" style="width:200px;"></input></td>
                    </tr>
                    <tr>
                        <td><span style="color: black;font-size: 20px;font-weight: 900">皮重</span></td>
                        <td><input class="easyui-textbox" type="text" name="tare" id="tare" style="width:200px;"></input></td>
                        <td><span style="color: black;font-size: 20px;font-weight: 900">皮重时间</span></td>
                        <td><input class="easyui-textbox" type="text" name="tareTime" id="tareTime" style="width:200px;"></input></td>
                    </tr>
                    <tr>
                        <td><span style="color: black;font-size: 20px;font-weight: 900">净重</span></td>
                        <td><input class="easyui-textbox" type="text" name="suttle" id="suttle" style="width:200px;"></input></td>
                        <td><span style="color: black;font-size: 20px;font-weight: 900">毛重司磅员</span></td>
                        <td><input class="easyui-textbox" type="text" name="grossWeightP" id="grossWeightP" style="width:200px;"></input></td>
                    </tr>
                    <tr>
                        <td><span style="color: black;font-size: 20px;font-weight: 900">卸货标记</span></td>
                        <td><input class="easyui-textbox" type="text" name="unloadSymbol" id="unloadSymbol" style="width:200px;"></input></td>
                        <td><span style="color: black;font-size: 20px;font-weight: 900">退货标记</span></td>
                        <td><input class="easyui-textbox" type="text" name="returnSymbol" id="returnSymbol" style="width:200px;" ></input></td>
                    </tr>
                    <tr>
                        <td><span style="color: black;font-size: 20px;font-weight: 900">退卸备注</span></td>
                        <td><input class="easyui-textbox" type="text" name="remarks1"  style="width:200px;"></input></td>
                        <td><span style="color: black;font-size: 20px;font-weight: 900">皮重司磅员</span></td>
                        <td><input class="easyui-textbox" type="text" name="tareP" id="tareP" style="width:200px;"></input></td>
                    </tr>
                </table>
            </div>

        </div>

        <div style="width:48%;">
            <div  style="text-align:center;background:#222222;height:180px;">
                <span id="info" style="color:#ff0509;line-height: 165px;font-size: 135px;m">晋A517R5</span>
            </div>
            <div id="pgrid" title="信息填报" closable="false" style="height:400px">

                <table cellpadding="5">
                    <tr>
                        <td><span style="color: black;font-size: 20px;font-weight: 900">供应商</span></td>
                        <td>
                            <select class="easyui-combobox" type="text" name="supplierName" id="supplierName" style="width:200px;" data-options="panelHeight:'auto',filter:filterCombo" >
                                <option value="-1"></option>
                                <#if supplier??>
                                    <#list supplier as s>
                                        <option value="${s.supplierId}">${s.supplierName}</option>
                                    </#list>
                                </#if>
                            </select>
                        </td>
                        <td><span style="color: black;font-size: 20px;font-weight: 900">采购商</span></td>
                        <td>
                            <select class="easyui-combobox" type="text" name="customerName" id="customerName" style="width:200px;" data-options="panelHeight:'auto',filter:filterCombo">
                                <option value="-1"></option>
                                <#if customer??>
                                    <#list customer as c>
                                        <option value="${c.customerId}">${c.customerName}</option>
                                    </#list>
                                </#if>
                            </select>
                        </td>
                    </tr>
                    <tr>
                        <td><span style="color: black;font-size: 20px;font-weight: 900">车号</span></td>
                        <td><input class="easyui-textbox" type="text" name="carId-f" id="carId-f"  style="width:200px;"></input></td>
                        <td><span style="color: black;font-size: 20px;font-weight: 900">物料</span></td>
                        <td>
                            <select class="easyui-combobox" type="text" name="materialName" id="materialName" style="width:200px;" data-options="panelHeight:'auto',filter:filterCombo">
                                <option value="-1"></option>
                                <#if materials??>
                                    <#list materials as m>
                                        <option value="${m.materialId}">${m.materialName}</option>
                                    </#list>
                                </#if>
                            </select>
                        </td>
                    </tr>
                    <tr>
                        <td><span style="color: black;font-size: 20px;font-weight: 900">原发毛重</span></td>
                        <td><input class="easyui-textbox" type="text" name="sourceGross" id="sourceGross" validType="number"   validType="number" style="width:200px;"></input></td>
                        <td><span style="color: black;font-size: 20px;font-weight: 900">原发皮重</span></td>
                        <td><input class="easyui-textbox" type="text" name="sourceTare" id="sourceTare"  validType="number" style="width:200px;" ></input></td>

                    </tr>
                    <tr>
                        <td><span style="color: black;font-size: 20px;font-weight: 900">原发净重</span></td>
                        <td><input class="easyui-textbox" type="text" name="sourceSuttle"  id="sourceSuttle" validType="number" style="width:200px;"></input></td>
                        <td><span style="color: black;font-size: 20px;font-weight: 900">备注</span></td>
                        <td><input class="easyui-textbox" type="text" name="remark2" id="remark2" style="width:200px;"></input></td>
                    </tr>
                    <tr>
                        <td><span style="color: black;font-size: 20px;font-weight: 900">车辆最大载重量</span></td>
                        <td><input class="easyui-textbox" type="text" name="max" id="max" disabled style="width:200px;"></input></td>
                    </tr>
                </table>
            </div>
        </div>
    </div>
</div>
</body>


<div id="dlg" class="easyui-dialog" style="width:800px;" data-options="closed:true,modal:true,border:'thin',buttons:'#dlg-buttons'">
    <form id="fm" method="post" novalidate style="padding:2px 2px 2px 2px">
        <table class="dv-table" style="width:100%;background:#fafafa;padding:5px;margin-top:5px;">
            <tr>
                <td style="width: 20%">车牌号</td>
                <td style="width: 80%">
                    <input name="carId" id="carId" validType="" class="easyui-textbox"  missingMessage="请输入" style="width:100%">
                </td>
            </tr>
            <tr>
                <td style="width: 20%">司机</td>
                <td style="width: 80%">
                    <input name="driver" id="driver" validType="" class="easyui-textbox"  missingMessage="请输入" style="width:100%">
                </td>
            </tr>
            <tr>
                <td style="width: 20%">驾驶证编号</td>
                <td style="width: 80%">
                    <input name="driverLicense" id="driverLicense" validType="" class="easyui-textbox"  missingMessage="请输入" style="width:100%">
                </td>
            </tr>
            <tr>
                <td style="width: 20%">行驶证号</td>
                <td style="width: 80%">
                    <input name="license" id="license" validType="" class="easyui-textbox"  missingMessage="请输入" style="width:100%">
                </td>
            </tr>
            <tr>
                <td style="width: 20%">从业资格证</td>
                <td style="width: 80%">
                    <input name="certificate" id="certificate" validType="" class="easyui-textbox"  missingMessage="请输入" style="width:100%">
                </td>
            </tr>
            <tr>
                <td style="width: 20%">道路运输许可证</td>
                <td style="width: 80%">
                    <input name="transportpermit" id="transportpermit" validType="" class="easyui-textbox"  missingMessage="请输入" style="width:100%">
                </td>
            </tr>
            <tr>
                <td style="width: 20%">车型</td>
                <td style="width: 80%">
                    <input name="carModel" id="carModel" validType="" class="easyui-textbox"  missingMessage="请输入" style="width:100%">
                </td>
            </tr>
            <tr>
                <td style="width: 20%">轴数</td>
                <td style="width: 80%">
                    <select class="easyui-combobox" type="text" name="axesNumber" id="axesNumber" style="width:100%">
                        <option value="-1">请选择</option>
                        <option value="2">2轴</option>
                        <option value="3">3轴</option>
                        <option value="4">4轴</option>
                        <option value="5">5轴</option>
                        <option value="6">6轴</option>
                    </select>
                </td>
            </tr>
            <tr>
                <td style="width: 20%">货车最大载重量</td>
                <td style="width: 80%">
                    <input name="careWeight" id="careWeight" validType="" class="easyui-textbox"  missingMessage="请输入" style="width:100%">
                </td>
            </tr>

        </table>
    </form>
</div>
<div id="dlg-buttons">
    <a href="javascript:void(0)" class="easyui-linkbutton c6" iconCls="icon-ok" onclick="save()" style="width:90px">保存</a>
    <a href="javascript:void(0)" class="easyui-linkbutton" iconCls="icon-cancel" onclick="javascript:$('#dlg').dialog('close')" style="width:90px">取消</a>
</div>

<!-- 读秤和车牌 -->
<script type="text/javascript">
    setInterval(function(){
        $.ajax({
            url : '/measure-info',
            async : true,
            success :function(data){
                $('#sec').html(data.sec);
                $('#info').html(data.car);
            }
        })
    }, 500);
    function filterCombo(q,row){
        var opts = $(this).combobox('options');
        var tmpValue = row.value;
        var tmpText = row.text;
        //Pinyin.GetQP是ChinesePYthon.js文件中定义的，目的是将汉语转化为对应的全拼，此处将转化后的拼音与输入的’p’进行筛选
        row.value = Pinyin.GetQP(row.value);
        row.text = Pinyin.GetQP(row.text);
        if(row[opts.textField].indexOf(q) == 0){
            //这里一定要把拼音转回来变成汉字，否则输入搜索的p以后，当遇到匹配的option并选中，传递回来的是汉语的全拼而非汉语本身。
            row.value = tmpValue;
            row.text = tmpText;
            return true;
        }else{
            row.value = tmpValue;
            row.text = tmpText;
            return false
        }
    }
</script>

<script type="text/javascript">
    $('#read').click(function(){
        $.ajax({
            url: '/measure-read',
            data :{'measureId':'JLD20190118132712'},
            async : false,
            success : function (data) {
                $('#measureId').textbox("setValue",data.measureId);
                $('#gross').textbox("setValue",data.grossWeight);
                $('#grossTime').textbox("setValue",data.grossWeightDate);
                $('#tare').textbox("setValue",data.tare);
                $('#tareTime').textbox("setValue",data.tareDate);
                $('#suttle').textbox("setValue",data.suttle);
                $('#grossWeightP').textbox("setValue",data.grossWeightP);
                $('#tareP').textbox("setValue", data.tareP);
                if(data.unloadSymbol=='1'){
                    $('#unloadSymbol').textbox("setValue",'已卸货');
                }else{
                    $('#unloadSymbol').textbox("setValue",'未卸货');
                }
                if(data.returnSymbol=='1'){
                    $('#returnSymbol').textbox("setValue",'已退货');
                }else{
                    $('#returnSymbol').textbox("setValue",'未退货');
                }
                $('#remarks1').textbox("setValue",data.remarks1);
                $('#supplierName').combobox('setValue', data.supplierName);
                $('#customerName').combobox('setValue', data.customerName);
                $('#materialName').combobox("setValue",data.materialName);
                $('#carId-f').textbox("setValue",data.carId);
                if(data.closeSymbol=='0'){
                    $('#closeSymbol').textbox("setValue", '未计量完');
                }else{
                    $('#closeSymbol').textbox("setValue", '计量完毕');
                }

                $('#sourceGross').textbox("setValue",data.sourceGross);
                $('#sourceTare').textbox("setValue",data.sourceTare);
                $('#sourceSuttle').textbox("setValue",data.sourceSuttle);
                $('#remark2').textbox("setValue",data.remark2);
            }
        })
    });
    $('#collection').click(function () {
        var car = $('#info').html();
        //YD00001 益达 //YL00001 益隆
        var supplierName = $('#supplierName').val();
        var customerName = $('#customerName').val();
        var time = getLocalTime();
        var measureId = $('#measureId').val();
        if(measureId==''){
            measureId = getMeasureId();
        }
        var weight = $('#sec').html();
        var people = '${user.nickname}';
        //请确认业务
        if((supplierName!='YD00001'&&supplierName!='YL00001')&&(customerName!='YD00001'&&customerName!='YL00001')){
            layer.msg('请确认业务', {icon: 2});
            return false;
        }
        if(supplierName=='-1'||customerName=='-1'){
            layer.msg('供应商和采购商必须全部填写完毕', {icon: 2});
            return false;
        }
        //供应商：销售业务,皮重,皮重时间，皮重司磅员
        if(supplierName=='YD00001'||supplierName=='YL00001'){
            var tareFirst = $('#tare').val();
            //第一次业务
            if(tareFirst==''||tareFirst=='0'){
                $('#tare').textbox("setValue", weight);
                $('#tareP').textbox("setValue",people);
                $('#tareTime').textbox("setValue", time);
            }else{
                $('#gross').textbox("setValue", weight);
                $('#grossWeightP').textbox("setValue",people);
                $('#grossTime').textbox("setValue", time)
            }
        }
        //收货商：采购业务,毛重,毛重时间，毛重司磅员
        if(customerName=='YD00001'||customerName=='YL00001'){
            var grossFirst = $('#gross').val();
            //第一次业务
            if(grossFirst==''||grossFirst=='0'){
                $('#gross').textbox("setValue", weight);
                $('#grossWeightP').textbox("setValue",people);
                $('#grossTime').textbox("setValue", time)
             //第二次业务
            }else{
                $('#tare').textbox("setValue", weight);
                $('#tareP').textbox("setValue",people);
                $('#tareTime').textbox("setValue", time);
            }


        }
        $('#measureId').textbox("setValue", measureId);
        $('#carId-f').textbox("setValue", car);
        $('#max').textbox("setValue",'');
        $.ajax({
            url : '/car-check/'+car,
            async: true,
            success: function(data){
                if(-1==data.code){
                    $('#dlg').dialog('open').dialog('center').dialog('setTitle','新增车辆');
                    $('#fm').form('clear');
                    $('#carId').textbox("setValue",car)
                }else{
                    var carObj = data.obj;
                    $('#max').textbox("setValue",carObj.careWeight);

                }
            }
        })
    })
    $('#reset').click(function () {
        init();
    });
    $('#save').click(function () {
        var measureId = $('#measureId').val();
        if(measureId==''){
            layer.msg('磅单号不存在，请确认', {icon: 2});
            return false;
        }
        var tareP = $('#tareP').val();
        var grossWeight = $('#gross').val();
        var grossTime = $('#grossTime').val();
        var tare = $('#tare').val();
        var tareTime = $('#tareTime').val();
        var suttle = $('#suttle').val();
        var grossWeightp = $('#grossWeightP').val();
        var unloadSymbol = $('#unloadSymbol').val();
        var returnSymbol = $('#returnSymbol').val();
        var remarks1 = $('#remarks1').val();
        var supplierName = $('#supplierName').val();
        var customerName = $('#customerName').val();
        var carId = $('#carId-f').val();
        var materialName = $('#materialName').val();
        var sourceGross = $('#sourceGross').val();
        var sourceTare = $('#sourceTare').val();
        var sourceSuttle = $('#sourceSuttle').val();
        var remark2 = $('#remark2').val();
        $.ajax({
            url : '/measure-save',
            data : {measureId:measureId,grossWeight:grossWeight,grossTime:grossTime,tare:tare,tareTime:tareTime,suttle:suttle,grossWeightp:grossWeightp
                ,unloadSymbol:unloadSymbol,returnSymbol:returnSymbol,remarks1:remarks1,supplierName:supplierName,tareP:tareP,
                customerName:customerName,carId:carId,materialName:materialName,sourceGross:sourceGross,sourceTare:sourceTare,sourceSuttle:sourceSuttle,remark2:remark2},
            async: false,
            success :function(data){

            }
        })

    });

</script>
<script type="text/javascript">
    function save() {
        $('#fm').form('submit',{
            url: '/car-ins-upd-del/-1',
            onSubmit: function(){
                return $(this).form('validate');
            },
            success: function(result){
                console.log(result)
                $('#dlg').dialog('close');        // close the dialog
                $('#max').textbox("setValue",result);
                // $('#car_table').datagrid('reload');    // reload the user data
            }
        });
    }
    function getLocalTime() {
        var myDate = new Date();
        var year=myDate.getFullYear();
        var month=myDate.getMonth()+1;
        var date=myDate.getDate();
        var h=myDate.getHours();       //获取当前小时数(0-23)
        var m=myDate.getMinutes();     //获取当前分钟数(0-59)
        var s=myDate.getSeconds();
        var now=year+'-'+getNow(month)+"-"+getNow(date)+" "+getNow(h)+':'+getNow(m)+":"+getNow(s);
        return now;
    }
    function getMeasureId(){
        var myDate = new Date();
        var year=myDate.getFullYear();
        var month=myDate.getMonth()+1;
        var date=myDate.getDate();
        var h=myDate.getHours();       //获取当前小时数(0-23)
        var m=myDate.getMinutes();     //获取当前分钟数(0-59)
        var s=myDate.getSeconds();
        var now="JLD"+year+getNow(month)+getNow(date)+getNow(h)+getNow(m)+getNow(s);
        return now;
    }
    function getNow(s) {
        return s < 10 ? '0' + s: s;
    }
</script>


<!-- 约束 -->
<script type="text/javascript">
    $.extend($.fn.validatebox.defaults.rules, {
        // 验证数字,整数或小数
        number : {
            validator : function(value) {
                return /^\d{1,10}(\.\d{0,4})?$/i.test(value);
            },
            message : '请输入正确的数字'
        }
    });
</script>

<script type="text/javascript">
    function init(){
        $('#measureId').textbox("setValue",'');
        $('#gross').textbox("setValue",'');
        $('#grossTime').textbox("setValue",'');
        $('#tare').textbox("setValue",'');
        $('#tareTime').textbox("setValue",'');
        $('#suttle').textbox("setValue",'');
        $('#grossWeightP').textbox("setValue",'');
        $('#unloadSymbol').textbox("setValue",'');
        $('#returnSymbol').textbox("setValue",'');
        $('#remarks1').textbox("setValue",'');
        $('#supplierName').textbox("setValue",'');
        $('#customerName').textbox("setValue",'');
        $('#carId-f').textbox("setValue",'');
        $('#materialName').textbox("setValue",'');
        $('#sourceGross').textbox("setValue",'');
        $('#sourceTare').textbox("setValue",'');
        $('#sourceSuttle').textbox("setValue",'');
        $('#remark2').textbox("setValue",'');
        $('#tareP').textbox("setValue", '');
        $('#max').textbox("setValue",'');
    }
</script>

</html>
